using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Example.Business;

namespace www
{
    public partial class Search_ByStyle : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void StyleDataSource_Select(object sender, NBusiness.Data.Web.SelectEntityEventArgs e)
        {
            e.Entities = BeerStyleCollection.FetchAll();
        }
        protected void DropDownList1_DataBound(object sender, EventArgs e)
        {
            int styleId;
            if (int.TryParse(Request["s"], out styleId) && styleId > 0)
            {
                DropDownList1.SelectedValue = styleId.ToString();
            }
        }
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.DataItem != null)
            {
                Beer b = (Beer)e.Row.DataItem;
                HyperLink companyLink = (HyperLink)e.Row.FindControl("CompanyLink");
                HyperLink availabilityLink = (HyperLink)e.Row.FindControl("AvailabilityLink");

                companyLink.Text = b.Company.Name;
                availabilityLink.Text = b.Availability.Text;
            }
        }
        protected void BeerDataSource_Select(object sender, NBusiness.Data.Web.SelectEntityEventArgs e)
        {
            int styleId;
            if (int.TryParse(Request["s"], out styleId) && styleId > 0)
            {
                int total;
                e.Entities = BeerCollection.FetchByBeerStyle(
                    styleId,
                    e.StartIndex,
                    e.MaxRows,
                    e.SortField,
                    e.SortOrder,
                    out total);
                e.TotalRows = total;
            }
        }
        protected void GoButton_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/Search/ByStyle.aspx?s=" + DropDownList1.SelectedValue);
        }
    }
}